package com.hollycrm.hollysqm.analyzer.solr.action.impl;

import com.hollycrm.hollysqm.analyzer.dic.DictionaryLoader;
import com.hollycrm.hollysqm.analyzer.solr.action.Act;
import com.hollycrm.hollysqm.analyzer.util.ConfigUtil;
import com.hollycrm.hollysqm.analyzer.util.Constant;
import lombok.extern.log4j.Log4j;

import java.sql.SQLException;

/**
 * Created by zhaihw on 2016/5/4.
 */
@Log4j
public class FlushDictionaryAct implements Act {
    /**
     * 执行方法
     */
    @Override
    public String execute() {
        String jsonTemp = ConfigUtil.getProp(Constant.jsonTemp);
        boolean b = false;
        String msg ;
        try {
            log.info("begin reload userDic");
            DictionaryLoader.getInstance().loadUserDic();
            log.info("begin reload stopDic");
            DictionaryLoader.getInstance().loadStopDic();
            b = true;
            msg = "success";
        } catch (SQLException e) {
            log.error("SQLException ",e);
            msg = "error,查询数据库记录出错";
        } catch (ClassNotFoundException e) {
            log.error("ClassNotFoundException ",e);
            msg = "error,加载驱动类出错";
        }
        return jsonTemp.replace("#1", String.valueOf(b)).replace("#2", msg);
    }
}
